/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* 顶部标题栏 */
.app-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px 20px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.8em;
    margin-bottom: 5px;
}

.app-header p {
    font-size: 0.9em;
    opacity: 0.9;
}

/* 主工作区域 - 三栏布局 */
.main-workspace {
    display: flex;
    flex: 1;
    height: calc(100vh - 80px);
    gap: 0;
}

/* 左侧面板 */
.left-panel {
    width: 300px;
    background: white;
    border-right: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* 中间画布 */
.center-canvas {
    flex: 1;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* 右侧面板 */
.right-panel {
    width: 320px;
    background: white;
    border-left: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* 面板标题 */
.panel-header {
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.panel-header h3 {
    font-size: 1.1em;
    color: #495057;
    margin: 0;
}

.canvas-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: #f8f9fa;
    border-radius: 5px;
    border: 1px solid #dee2e6;
}

.zoom-controls button {
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
}

#zoomDisplay {
    min-width: 50px;
    text-align: center;
    font-weight: 600;
    color: #495057;
    font-size: 0.9em;
}

.overlap-controls {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    background: #f8f9fa;
    border-radius: 5px;
    border: 1px solid #dee2e6;
}

.overlap-switch {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 8px;
}

.overlap-switch input[type="checkbox"] {
    display: none;
}

.overlap-switch-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background-color: #ccc;
    border-radius: 12px;
    transition: background-color 0.3s;
}

.overlap-switch-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.overlap-switch input:checked + .overlap-switch-slider {
    background-color: #007bff;
}

.overlap-switch input:checked + .overlap-switch-slider::before {
    transform: translateX(20px);
}

.overlap-switch-label {
    font-size: 0.9em;
    font-weight: 500;
    color: #495057;
}

/* 按钮样式 */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #218838;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
    margin-bottom: 8px;
}

/* 左侧面板样式 */
.upload-area {
    margin: 15px;
    border: 2px dashed #007bff;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8f9ff;
}

.upload-area:hover {
    border-color: #0056b3;
    background-color: #e3f2fd;
}

.upload-area.dragover {
    border-color: #28a745;
    background-color: #f0fff4;
}

.upload-content .upload-icon {
    font-size: 2em;
    margin-bottom: 8px;
    display: block;
}

.upload-content p {
    margin-bottom: 8px;
    color: #666;
    font-size: 0.9em;
}

.uploaded-files-list {
    padding: 0 15px;
    max-height: 120px;
    overflow-y: auto;
}

.file-item {
    background: #f8f9fa;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 6px;
    border-left: 3px solid #007bff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.file-name {
    font-size: 0.85em;
    font-weight: 500;
    color: #333;
}

.file-info {
    font-size: 0.75em;
    color: #666;
}

.source-pages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.section-title {
    padding: 10px 15px;
    font-weight: 600;
    color: #495057;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
}

.source-pages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    align-content: start;
}

.page-item {
    border: 2px solid #ddd;
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.page-item:hover {
    border-color: #007bff;
    box-shadow: 0 2px 8px rgba(0,123,255,0.2);
}

.page-item.selected {
    border-color: #007bff;
    background-color: #e3f2fd;
}

.page-thumbnail {
    width: 100%;
    max-width: 100px;
    height: auto;
    border-radius: 4px;
    margin-bottom: 6px;
}

.page-info {
    font-size: 0.75em;
    color: #666;
}

.page-info div {
    margin-bottom: 2px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

/* 中间画布样式 */
.canvas-area {
    flex: 1;
    position: relative;
    overflow: auto;
    background: #f8f9fa;
    background-image: 
        radial-gradient(circle, #e9ecef 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.canvas-empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #6c757d;
}

.empty-icon {
    font-size: 3em;
    margin-bottom: 15px;
}

.canvas-empty-state h4 {
    margin-bottom: 15px;
    color: #495057;
}

.canvas-empty-state p {
    margin-bottom: 5px;
    font-size: 0.9em;
}

.canvas-pages {
    position: relative;
    min-height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.canvas-page-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.canvas-page {
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: visible;
    position: relative;
}

.canvas-page.active {
    border-color: #007bff;
    box-shadow: 0 4px 12px rgba(0,123,255,0.2);
}

.canvas-page-header {
    background: #f8f9fa;
    padding: 10px 15px;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.canvas-page-title {
    font-weight: 600;
    color: #495057;
}

.canvas-page-content {
    position: relative;
    background: white;
    border: 1px solid #e9ecef;
    overflow: visible;
}

.canvas-page-drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px dashed #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 0.9em;
    transition: all 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.canvas-page-drop-zone.has-elements {
    border: none;
    background: transparent;
}

.canvas-page-drop-zone.drag-over {
    border-color: #28a745;
    background-color: rgba(40, 167, 69, 0.1);
    color: #28a745;
}

.canvas-element {
    position: absolute;
    border: 2px solid #dee2e6;
    cursor: move;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border-radius: 4px;
    overflow: hidden;
    transition: all 0.2s ease;
    user-select: none;
}

.canvas-element:hover {
    border-color: #007bff;
    box-shadow: 0 4px 12px rgba(0,123,255,0.2);
    transform: translateZ(0);
}

.canvas-element.selected {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.3);
}

.canvas-element img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
}

.element-resize-handles {
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border: 2px solid #007bff;
    pointer-events: none;
}

.element-resize-handles::before,
.element-resize-handles::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: #007bff;
    border-radius: 50%;
}

.element-resize-handles::before {
    top: -4px;
    left: -4px;
}

.element-resize-handles::after {
    bottom: -4px;
    right: -4px;
}

/* 右侧面板样式 */
.right-panel {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.settings-section {
    padding: 15px;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
}

.settings-section h4 {
    margin-bottom: 10px;
    color: #495057;
    font-size: 1em;
}

.tab-panel-content h5 {
    margin-bottom: 10px;
    margin-top: 15px;
    color: #495057;
    font-size: 0.95em;
    font-weight: 600;
}

.tab-panel-content h5:first-child {
    margin-top: 0;
}

.size-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.size-presets {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.size-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.size-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.size-input-row input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}

.size-input-row span {
    color: #666;
    font-weight: 500;
    min-width: 30px;
}

.size-apply-btn {
    width: 100%;
    margin-top: 5px;
}

.element-settings {
    min-height: 50px;
}

.no-selection {
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 20px;
}

.generate-section {
    padding: 15px;
    background: #f8f9fa;
    margin-top: auto;
    flex-shrink: 0;
}

.generate-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-input {
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 0.9em;
}

.btn span {
    margin-right: 5px;
}

/* PDF页面结构设置样式 */
.pdf-settings {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.page-count-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.count-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.count-controls span {
    min-width: 30px;
    text-align: center;
    font-weight: 600;
    color: #495057;
}

/* 标签页样式 */
.tabs-navigation {
    display: flex;
    background: #f8f9fa;
    border-bottom: 2px solid #e9ecef;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 12px 10px;
    border: none;
    background: transparent;
    color: #6c757d;
    font-size: 0.85em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    position: relative;
}

.tab-btn:hover {
    background: #e9ecef;
    color: #495057;
}

.tab-btn.active {
    color: #007bff;
    background: white;
    border-bottom: 3px solid #007bff;
    font-weight: 600;
}

.tabs-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.tab-panel {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.tab-panel.active {
    display: flex;
}

.tab-panel-header {
    padding: 12px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    flex-shrink: 0;
}

.tab-panel-content {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
}

.pdf-pages-section {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-bottom: 1px solid #e9ecef;
}

.section-title {
    padding: 10px 15px;
    font-weight: 600;
    color: #495057;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.pdf-pages-list {
    overflow-y: auto;
    padding: 10px;
    flex: 1;
}

.pdf-page-item {
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.pdf-page-item:hover {
    border-color: #007bff;
    box-shadow: 0 2px 4px rgba(0,123,255,0.2);
}

.pdf-page-item.active {
    border-color: #007bff;
    background-color: #e3f2fd;
}

.pdf-page-thumbnail {
    width: 40px;
    height: 56px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    color: #6c757d;
    flex-shrink: 0;
}

.pdf-page-info {
    flex: 1;
    min-width: 0;
}

.pdf-page-title {
    font-weight: 600;
    color: #495057;
    font-size: 0.9em;
    margin-bottom: 2px;
}

.pdf-page-size {
    color: #6c757d;
    font-size: 0.8em;
}

.pdf-page-controls {
    display: flex;
    gap: 4px;
}

.current-page-info {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    font-size: 0.9em;
    color: #495057;
}

.canvas-page-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 123, 255, 0.9);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 600;
}

/* 章节样式 */
section {
    background: white;
    margin-bottom: 20px;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

section h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.5em;
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
}

/* 文件上传区域 */
.upload-area {
    border: 2px dashed #007bff;
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
}

.upload-area:hover {
    border-color: #0056b3;
    background-color: #f8f9ff;
}

.upload-area.dragover {
    border-color: #28a745;
    background-color: #f0fff4;
}

.upload-content .upload-icon {
    font-size: 3em;
    margin-bottom: 10px;
    display: block;
}

.upload-content p {
    font-size: 1.1em;
    color: #666;
}

/* 已上传文件列表 */
.uploaded-files {
    display: grid;
    gap: 15px;
}

.file-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #007bff;
}

.file-header {
    display: flex;
    justify-content: between;
    align-items: center;
    margin-bottom: 10px;
}

.file-name {
    font-weight: 600;
    color: #333;
}

.file-info {
    color: #666;
    font-size: 0.9em;
}

/* 源页面预览 */
.source-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
    max-height: 600px;
    overflow-y: auto;
}

.page-item {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
}

.page-item:hover {
    border-color: #007bff;
    box-shadow: 0 2px 8px rgba(0,123,255,0.2);
}

.page-item.selected {
    border-color: #007bff;
    background-color: #e3f2fd;
}

.page-thumbnail {
    width: 100%;
    max-width: 150px;
    height: auto;
    border-radius: 4px;
    margin-bottom: 8px;
}

.page-info {
    font-size: 0.85em;
    color: #666;
}

.page-info div {
    margin-bottom: 2px;
}

/* 目标页面配置 */
.target-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-size-presets {
    display: flex;
    align-items: center;
    gap: 5px;
}

.target-pages {
    display: grid;
    gap: 20px;
}

.target-page {
    border: 2px solid #007bff;
    border-radius: 8px;
    padding: 20px;
    background: #f8f9ff;
}

.target-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.target-page-title {
    font-weight: 600;
    color: #007bff;
}

.target-page-content {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 20px;
}

.target-page-config {
    background: white;
    padding: 15px;
    border-radius: 6px;
}

.config-item {
    margin-bottom: 10px;
}

.config-item label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.config-item input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.source-pages-list {
    background: white;
    padding: 15px;
    border-radius: 6px;
    min-height: 200px;
    border: 2px dashed #ddd;
}

.source-pages-list.drop-zone {
    border-color: #28a745;
    background-color: #f0fff4;
}

.source-page-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #007bff;
}

.source-page-thumbnail {
    width: 40px;
    height: 56px;
    object-fit: cover;
    border-radius: 3px;
}

.source-page-info {
    flex: 1;
    font-size: 0.9em;
}

.source-page-controls {
    display: flex;
    gap: 5px;
}

/* 生成控制区域 */
.generate-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.generate-controls input {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    flex: 1;
    min-width: 200px;
}

/* 弹窗样式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 10px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.close {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: #999;
}

.close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.config-group {
    margin-bottom: 20px;
}

.config-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: #333;
}

.size-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
}

.size-inputs input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.transform-inputs .input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.transform-inputs .input-row label {
    width: 120px;
    margin-bottom: 0;
    font-weight: 500;
}

.transform-inputs .input-row input {
    flex: 1;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* 加载动画 */
.loading {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
}

.loading-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: white;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 空状态消息 */
.empty-message {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 40px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    header h1 {
        font-size: 2em;
    }
    
    .target-page-content {
        grid-template-columns: 1fr;
    }
    
    .generate-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .generate-controls input {
        min-width: auto;
    }
    
    .source-pages {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* 拖拽相关样式 */
.dragging {
    opacity: 0.5;
}

.drop-target {
    border-color: #28a745 !important;
    background-color: #f0fff4 !important;
}
